Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@types/supertest
Advanced tools
The @types/supertest package provides TypeScript type definitions for the Supertest library, which is a SuperAgent driven library for testing HTTP servers. These type definitions allow developers to use Supertest in TypeScript projects with the benefits of type checking and IntelliSense in their code editors.
HTTP Assertions
This feature allows you to make HTTP assertions with Supertest. The code sample demonstrates how to test a GET request to '/user' endpoint expecting a JSON response and a 200 status code.
import supertest from 'supertest';
import app from './app';
describe('GET /user', () => {
it('responds with json', (done) => {
supertest(app)
.get('/user')
.expect('Content-Type', /json/)
.expect(200, done);
});
});
Type Checking
This feature provides type checking for Supertest objects. The code sample shows how to create a typed Supertest instance and use it to make a GET request.
import supertest, { SuperTest, Test } from 'supertest';
import app from './app';
const request: SuperTest<Test> = supertest(app);
request.get('/user').expect(200);
Chai-HTTP is a plugin for the Chai assertion library that enables HTTP assertions. It is similar to Supertest in that it allows for testing HTTP servers, but it is designed to work seamlessly with Chai's assertion methods.
Axios is a promise-based HTTP client for the browser and Node.js. While not specifically designed for testing like Supertest, it can be used in tests to make HTTP requests and handle responses.
Nock is an HTTP server mocking and expectations library for Node.js. It allows developers to test modules that perform HTTP requests in isolation, by intercepting requests and providing programmed responses. Unlike Supertest, which performs actual HTTP requests, Nock intercepts and simulates them.
Jest Fetch Mock allows you to mock the fetch API in Jest tests, providing a way to test components that make fetch calls without making real HTTP requests. It is similar to Nock but designed to work with Jest and the fetch API.
npm install --save @types/supertest
This package contains type definitions for supertest (https://github.com/visionmedia/supertest).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/supertest.
import * as superagent from "superagent";
export = supertest;
declare function supertest(app: any, options?: supertest.Options): supertest.SuperTest<supertest.Test>;
declare namespace supertest {
interface Response extends superagent.Response {}
interface Request extends superagent.SuperAgentRequest {}
type CallbackHandler = (err: any, res: Response) => void;
interface Test extends superagent.SuperAgentRequest {
app?: any;
url: string;
serverAddress(app: any, path: string): string;
expect(status: number, callback?: CallbackHandler): this;
expect(status: number, body: any, callback?: CallbackHandler): this;
expect(checker: (res: Response) => any, callback?: CallbackHandler): this;
expect(body: string, callback?: CallbackHandler): this;
expect(body: RegExp, callback?: CallbackHandler): this;
expect(body: Object, callback?: CallbackHandler): this;
expect(field: string, val: string, callback?: CallbackHandler): this;
expect(field: string, val: RegExp, callback?: CallbackHandler): this;
end(callback?: CallbackHandler): this;
}
interface Options {
http2?: boolean;
}
interface AgentOptions extends Options {
ca?: any;
}
function agent(app?: any, options?: AgentOptions): SuperAgentTest;
interface SuperTest<T extends superagent.SuperAgentRequest> extends superagent.SuperAgent<T> {}
interface SuperTestWithHost<T extends superagent.SuperAgentRequest> extends SuperTest<T> {
host(host: string): this;
}
type SuperAgentTest =
& SuperTestWithHost<Test>
& Pick<
Request,
| "use"
| "on"
| "set"
| "query"
| "type"
| "accept"
| "auth"
| "withCredentials"
| "retry"
| "ok"
| "redirects"
| "timeout"
| "buffer"
| "serialize"
| "parse"
| "ca"
| "key"
| "pfx"
| "cert"
>;
}
These definitions were written by Alex Varju, and Petteri Parkkila.
FAQs
TypeScript definitions for supertest
The npm package @types/supertest receives a total of 3,668,991 weekly downloads. As such, @types/supertest popularity was classified as popular.
We found that @types/supertest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.